//
//  ByViewSelectServiceHaved.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/12/12.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewSelectServiceHaved.h"

#import "ByViewCannotAppointBecauseNotHave.h"

@implementation ByViewSelectServiceHaved
{
    NSInteger _curIndex;
    
    NSArray *_items;
}
- (instancetype)init {
    
    if (self = [super init]) {
    
        self.position = JKBombViewPositionMid;
        self.damping = 0.8;
    
        _curIndex = 0;
        _items = @[@"套餐1", @"套餐2", @"套餐3"];
        
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH * 0.6, 180)];
    contentView.backgroundColor = [UIColor whiteColor];
    contentView.layer.cornerRadius = 12;
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"请选择您已购买的体检服务";
    titleLabel.font = FONT(14);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor blackColor];
    [contentView addSubview:titleLabel];
    
    UIPickerView *picker = [UIPickerView new];
    picker.delegate = self;
    picker.dataSource = self;
    picker.showsSelectionIndicator = true;
    [contentView addSubview:picker];
    
    UIButton *comfirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    comfirmButton.backgroundColor = rgba(149, 214, 250, 1);
    comfirmButton.titleLabel.font = FONT(14);
    comfirmButton.layer.cornerRadius = 15;
    [comfirmButton setTitle:@"确认体检服务" forState:UIControlStateNormal];
    [comfirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [comfirmButton addTarget:self action:@selector(comfirm) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:comfirmButton];
    
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@20);
        make.left.right.equalTo(@0);
        make.height.equalTo(@20);
    }];
    [picker mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom);
        make.bottom.equalTo(comfirmButton.mas_top);
        make.left.right.equalTo(@0);
    }];
    [comfirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@-15);
        make.height.equalTo(@30);
        make.width.equalTo(contentView).multipliedBy(0.5);
        make.centerX.equalTo(@0);
    }];
    
    
    self.contentView = contentView;
}

- (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView {
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return 3;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view {
    
    if (!view) {
        UILabel *label = [UILabel new];
        label.font = FONT(16);
        
        view = label;
    }
    UILabel *label = (UILabel *)view;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = _items[row];
    if (row == _curIndex) {
        label.textColor = rgba(149, 214, 250, 1);
    } else {
        label.textColor = [UIColor grayColor];
    }
    return label;
};
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    _curIndex = row;
    [pickerView reloadComponent:0];
}

- (void)comfirm {
    
    [self hide];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        ByViewCannotAppointBecauseNotHave *view = [ByViewCannotAppointBecauseNotHave new];
        [view show];
    });
    
    
}

@end
